<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

//自定义的手机校验规则
class Phone implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $reg1 = '/^\+86-1[3-9]\d{9}$/';
        $reg2 = '/^1[3-9]\d{9}$/';
        return preg_match($reg1,$value) || preg_match($reg2,$value);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '手机号 必须为正确的.';
    }
}
